<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>支付系统并发处理解决方案</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .problem-card {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
        }
        .solution-card {
            background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
        }
        .number-circle {
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-weight: bold;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .fade-in {
            animation: fadeIn 0.8s ease-out;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-gradient-to-br from-purple-600 via-indigo-600 to-blue-600 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 fade-in">
                <i class="fas fa-credit-card mr-4"></i>支付系统并发处理
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 fade-in" style="animation-delay: 0.2s;">
                当微信与支付宝相遇：解决同时支付的技术挑战
            </p>
            <div class="flex justify-center space-x-8 text-4xl fade-in" style="animation-delay: 0.4s;">
                <i class="fab fa-weixin opacity-80"></i>
                <i class="fas fa-plus opacity-60"></i>
                <i class="fab fa-alipay opacity-80"></i>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 110C120 100 240 80 360 70C480 60 600 60 720 65C840 70 960 80 1080 85C1200 90 1320 90 1380 90L1440 90V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0V120Z" fill="#F9FAFB"/>
            </svg>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="container mx-auto px-6 py-16">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 card-hover">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap serif-font">在</span>处理支付系统时，如果用户同时在微信和支付宝上对同一笔订单进行支付，这会导致一系列潜在的问题。这种情况不仅会影响订单的准确性，还可能对系统的财务和用户体验产生负面影响。
                </p>
            </div>
        </div>
    </section>

    <!-- Problem Section -->
    <section class="container mx-auto px-6 py-16">
        <div class="text-center mb-12">
            <h2 class="text-4xl font-bold gradient-text mb-4">问题说明</h2>
            <p class="text-xl text-gray-600">当用户同时通过微信和支付宝完成支付时，系统会收到两个支付请求</p>
        </div>

        <div class="grid md:grid-cols-2 gap-8 max-w-6xl mx-auto">
            <div class="problem-card rounded-2xl p-8 card-hover">
                <div class="flex items-start mb-4">
                    <div class="number-circle mr-4">1</div>
                    <div>
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">重复支付</h3>
                        <p class="text-gray-700">同一笔订单的金额可能会被支付两次，导致系统需要处理重复支付的情况。</p>
                    </div>
                </div>
            </div>

            <div class="problem-card rounded-2xl p-8 card-hover">
                <div class="flex items-start mb-4">
                    <div class="number-circle mr-4">2</div>
                    <div>
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">订单状态不一致</h3>
                        <p class="text-gray-700">系统可能会出现订单状态不同步的问题，例如一个支付请求可能更新了订单状态，而另一个支付请求则没有。</p>
                    </div>
                </div>
            </div>

            <div class="problem-card rounded-2xl p-8 card-hover">
                <div class="flex items-start mb-4">
                    <div class="number-circle mr-4">3</div>
                    <div>
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">数据一致性问题</h3>
                        <p class="text-gray-700">如果没有妥善处理，可能会导致数据库中的订单信息不一致，从而影响后续的订单处理流程。</p>
                    </div>
                </div>
            </div>

            <div class="problem-card rounded-2xl p-8 card-hover">
                <div class="flex items-start mb-4">
                    <div class="number-circle mr-4">4</div>
                    <div>
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">财务处理</h3>
                        <p class="text-gray-700">重复支付会导致实际到账金额与系统记录不一致，增加财务核对的复杂度。</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section class="bg-white py-16">
        <div class="container mx-auto px-6">
            <h3 class="text-3xl font-bold text-center mb-12 gradient-text">支付流程可视化</h3>
            <div class="mermaid">
                graph TD
                    A[用户发起支付] --> B{选择支付方式}
                    B -->|微信支付| C[微信支付请求]
                    B -->|支付宝支付| D[支付宝支付请求]
                    C --> E[支付系统处理]
                    D --> E
                    E --> F{检查订单状态}
                    F -->|未支付| G[更新订单状态]
                    F -->|已支付| H[拒绝重复支付]
                    G --> I[支付成功]
                    H --> J[返回已支付提示]
                    
                    style A fill:#f9f,stroke:#333,stroke-width:2px
                    style I fill:#9f9,stroke:#333,stroke-width:2px
                    style J fill:#ff9,stroke:#333,stroke-width:2px
            </div>
        </div>
    </section>

    <!-- Solution Section -->
    <section class="container mx-auto px-6 py-16">
        <div class="text-center mb-12">
            <h2 class="text-4xl font-bold gradient-text mb-4">解决方案</h2>
            <p class="text-xl text-gray-600">为了解决用户在微信和支付宝同时支付同一笔订单的问题，可以采取以下策略</p>
        </div>

        <div class="space-y-8 max-w-5xl mx-auto">
            <!-- Solution 1 -->
            <div class="bg-gradient-to-r from-blue-50 to-purple-50 rounded-2xl p-8 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-fingerprint text-3xl text-purple-600 mr-4"></i>
                    <h3 class="text-2xl font-bold text-gray-800">唯一订单号检查</h3>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white rounded-lg p-6">
                        <h4 class="font-bold text-lg mb-2 text-purple-600">全局唯一性</h4>
                        <p class="text-gray-700">在生成订单时，为每笔订单生成一个全局唯一的订单号。在支付回调时，系统应检查该订单号是否已存在或已被处理。</p>
                    </div>
                    <div class="bg-white rounded-lg p-6">
                        <h4 class="font-bold text-lg mb-2 text-purple-600">支付状态检查</h4>
                        <p class="text-gray-700">在处理支付请求时，检查该订单号的支付状态，如果已支付则忽略后续的支付请求。</p>
                    </div>
                </div>
            </div>

            <!-- Solution 2 -->
            <div class="bg-gradient-to-r from-green-50 to-blue-50 rounded-2xl p-8 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-shield-alt text-3xl text-green-600 mr-4"></i>
                    <h3 class="text-2xl font-bold text-gray-800">幂等性设计</h3>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white rounded-lg p-6">
                        <h4 class="font-bold text-lg mb-2 text-green-600">幂等操作</h4>
                        <p class="text-gray-700">确保支付操作是幂等的，即重复支付不会改变最终的处理结果。通过设置幂等标识（如支付请求的唯一 ID），避免同一请求被重复处理。</p>
                    </div>
                    <div class="bg-white rounded-lg p-6">
                        <h4 class="font-bold text-lg mb-2 text-green-600">数据库锁定</h4>
                        <p class="text-gray-700">在处理支付请求时，对订单记录加锁，防止在处理过程中出现并发问题。</p>
                    </div>
                </div>
            </div>

            <!-- Solution 3 -->
            <div class="bg-gradient-to-r from-yellow-50 to-orange-50 rounded-2xl p-8 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-sync-alt text-3xl text-orange-600 mr-4"></i>
                    <h3 class="text-2xl font-bold text-gray-800">支付回调处理</h3>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white rounded-lg p-6">
                        <h4 class="font-bold text-lg mb-2 text-orange-600">异步处理</h4>
                        <p class="text-gray-700">将支付回调处理设置为异步任务，确保系统能够处理高并发的支付请求。</p>
                    </div>
                    <div class="bg-white rounded-lg p-6">
                        <h4 class="font-bold text-lg mb-2 text-orange-600">回调幂等性</h4>
                        <p class="text-gray-700">对支付回调进行幂等性处理，确保即使支付回调被多次触发，也不会对系统造成重复处理的影响。</p>
                    </div>
                </div>
            </div>

            <!-- Solution 4 -->
            